package com.five.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.five.common.entity.LoginTable;
import com.five.common.dao.LoginTableMapper;
import com.five.common.entity.ModPasswordDTO;
import com.five.common.entity.StudentLoginer;
import com.five.common.service.LoginTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ywt
 * @since 2024-07-18
 */
@Service
public class LoginTableServiceImpl extends ServiceImpl<LoginTableMapper, LoginTable> implements LoginTableService {
    @Autowired
    private LoginTableMapper loginTableMapper;

    @Override
    public LoginTable login(String phone, String password, String verifyCode) {
        QueryWrapper<LoginTable> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone)
                .eq("password", password);
        LoginTable loginTable = loginTableMapper.selectOne(queryWrapper);
        return loginTable;
    }

    @Override
    public Integer addStudentLoginer(StudentLoginer studentLoginer) {
        return loginTableMapper.addStudentLoginer(studentLoginer);
    }

    @Override
    public LoginTable getLoginInfo(String phone) {
        return loginTableMapper.getLoginInfo(phone);
    }

    @Override
    public int modAvatarOrPhone(String avatar, Integer id) {
        UpdateWrapper<LoginTable> wrapper = new UpdateWrapper<>();
        wrapper.set(avatar != null, "avatar", avatar)
                .eq("id", id);
        return loginTableMapper.update(wrapper);
    }

    @Override
    public int modPassword(ModPasswordDTO modPasswordDTO) {
       return loginTableMapper.modPassword(modPasswordDTO);
    }
}